package com.xkcyy.study.spring.d02_registry.s01_bean_definition;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Profile;

/**
 * S01_BeanDefinitionApplication
 *
 * @author yuand
 * @date 2021/6/7
 **/
public class S01_BeanDefinitionApplication {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        RootBeanDefinition bd = new RootBeanDefinition(UserService.class);
        context.registerBean(UserService.class);
        context.refresh();
        UserService bean = context.getBean(UserService.class);
        OrgService orgService = context.getBean(OrgService.class);
    }

    @Import(OrgService.class)
    static class UserService {

    }

    static class OrgService {

    }

    static class UserServiceFactoryBean implements FactoryBean<OrgService> {

        @Override
        public OrgService getObject() throws Exception {
            return new OrgService();
        }

        @Override
        public Class<?> getObjectType() {
            return OrgService.class;
        }
    }
}
